<template>
  <div class="shopcartlist">
    <!-- 头部信息 -->
    <div class="header">
      <i class="iconfont icon-xiangzuojiantou back" @click="back"></i>
      <input class="check" type="checkbox" v-model="isSelectAll" @change="selectAll()" />
      <span class="label">当当网</span>
    </div>
    <!-- 购物车图书列表 -->
    <div class="items">
      <div
        class="item"
        v-for="(shopcartitem, index) in getShopCartList"
        :key="shopcartitem.shopcartid"
      >
        <div class="content">
          <input @change="checkEveryCheckbox" type="checkbox" class="check" v-model="shopcartitem.checked" />
          <div class="pic">
            <img :src="ImgUtil.getImg(shopcartitem.bookpicname)" />
          </div>
          <div class="descri">
            <div class="book-title">{{ shopcartitem.bookname }}</div>
            <div class="price">
              <span class="curprice">&yen; {{ shopcartitem.bookprice }}</span>
              <span class="addsubtrcbktosc">
                <addsubtrsc :shopcart="shopcartitem"></addsubtrsc>
              </span>
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 结算信息 -->
    <div class="cal">
      <span class="checkall">
        <input class="check" type="checkbox"  v-model="isSelectAll" @change="selectAll()" />
        <span class="selall">全选</span>
        <span class="total">
          合计：
          <span class="money">&yen; {{ totalPrice }}</span>
        </span>
      </span>
      <span class="pay">去结算 {{ totalCount }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import ImgUtil from "@/utils/imgutil"
import shopcartclass from "@/piniaviews/books/service/shopcart"
import addsubtrsc from "../books/components/addsubtrsc.vue"
const {
  storeRefs: { getShopCartList },
  refreshShopCartList,
  back,
  isSelectAll,
  selectAll,
  checkEveryCheckbox, // 购物列表中图书事件
} = shopcartclass
const { totalCount, totalPrice } = refreshShopCartList()
</script>

<style lang="scss" scoped>
.shopcartlist {
  /* 头部内容 */
  .header {
    position: fixed;
    z-index: 1;
    height: 0.85rem;
    width: 5.14rem;
    display: flex;
    align-items: center;
    column-gap: 0.25rem;
    padding: 0 0.13rem;
    .back,
    .label {
      font-size: 0.25rem;
    }
    .check {
      width: 0.3rem;
      height: 0.3rem;
      cursor: pointer;
    }
  }
  /* 图书列表 */
  .items {
    position: absolute;
    top: 0.86rem;
    bottom: 0.865rem;
    display: grid;
    grid-template-columns: 5.14rem;
    grid-auto-rows: 2.89rem; /* 隐式网格高度 */
    overflow-y: scroll;
    .item {
      .content {
        display: flex;
        align-items: center;
        .check {
          width: 0.33rem;
          height: 0.33rem;
        }
        .pic {
          width: 1.539rem;
          height: 2.16rem;
          display: flex;
          align-items: center;
          justify-content: center;
          img {
            width: 80%;
            height: 70%;
          }
        }
        .descri {
          width: 3.21rem;
          .book-title {
            height: 0.8rem;
            color: #272727;
          }
          .price {
            height: 1rem;
            color: red;
            display: flex;
            align-items: center;
            font-size: 0.2rem;

            .curprice {
              flex-grow: 1;
            }
            .addsubtrcbktosc {
              flex-grow: 2;
            }
          }
        }
      }
    }
  }
  /* 底部内容 */
  .cal {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 5.14rem;
    height: 0.86rem;
    margin: 0 0.13rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    background-color: #fff;
    font-size: 0.22rem;
    .checkall {
      display: flex;
      column-gap: 0.1rem;
      .check {
        width: 0.33rem;
        height: 0.33rem;
        cursor: pointer;
      }
      .total {
        font-weight: bold;
      }
    }
    .pay {
      background-color: #ed1611;
      height: 0.6rem;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 1.8rem;
      color: #fff;
      border-radius: 0.288rem;
      text-shadow: 0 0 0.01rem #3f3f3f;
      margin-right: 0.13rem;
    }
  }
}
</style>
